package org.springsocial.services.impl;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springsocial.dao.PlayerDao;
import org.springsocial.domain.Player;
import org.springsocial.services.PlayerService;
import org.springsource.util.ActiveTweeter;

@Service
public class PlayerServiceImpl implements PlayerService{
	
	@Autowired
	private PlayerDao playerDao;

	@Override
	public Player getPlayer(Long id) {
		return playerDao.getPlayer(id);
	}

	@Override
	public List<Player> getAll() {
		return playerDao.getAll();
	}

	@Override
	public List<Long> getPlayerIds(ActiveTweeter activeTweeter) {
		return playerDao.getPlayerIds(activeTweeter);
	}

	@Override
	public Player getPlayerWithTweets(Long playerId,ActiveTweeter activeTweeter) {
		return playerDao.getPlayerWithTweets(playerId,activeTweeter);
	}

	@Override
	public Player getPlayerWithTweetsFromToDate(Long playerId, Date from,
			Date to) {
		return playerDao.getPlayerWithTweetsFromToDate(playerId, from, to);
	}

	@Override
	public Player getPlayerWithTweetsFromLastDays(Long playerId,
			int numberOfDays) {
		Calendar from = Calendar.getInstance();
		Calendar to = Calendar.getInstance();
		from.add(Calendar.DAY_OF_MONTH, -numberOfDays);
		from.set(Calendar.HOUR_OF_DAY, 00);
		from.set(Calendar.MINUTE, 00);
		from.set(Calendar.SECOND, 00);
		from.set(Calendar.MILLISECOND, 00);
		
		to.set(Calendar.HOUR_OF_DAY,23);
		to.set(Calendar.MINUTE, 59);
		to.set(Calendar.SECOND, 59);
		to.set(Calendar.MILLISECOND, 00);
		
		System.out.println("getPlayerWithTweetsFromLastDays from"+from.getTime());
		System.out.println("getPlayerWithTweetsFromLastDays to"+to.getTime());
		return playerDao.getPlayerWithTweetsFromToDate(playerId, from.getTime(), to.getTime());
	}

	@Override
	public Player getPlayerWithTweetsFromLastMonths(Long playerId,
			int numberOfMonths) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Player updatePlayer(Player player) {
		playerDao.updatePlayer(player);
		return player;
	}

	@Override
	public Player savePlayer(Player player) {
		return playerDao.savePlayer(player);
	}

	@Override
	public Player deletePlayer(Player player) {
		playerDao.deletePlayer(player);
		return player;
	}

}
